<?php

$config = array(
    'theme'      => 'bds',
    'name'       => 'KTD',
    'language'   => 'vi',
    'import'     => array(
        'application.models.*',
        'application.models.users.*',
        'application.components.*',
    ),
    'modules'    => array(
        'quanly',
        'gii' => array(
            'class'    => 'system.gii.GiiModule',
            'password' => '123456',
        ),
    ),
    'params'     => require (dirname(__FILE__) . DIRECTORY_SEPARATOR . 'params.php'),
    'components' => array(
        'urlManager'   => require(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'url.php'),
        'user'         => array(
            'allowAutoLogin' => true,
        ),
        'cache'        => array(
            'class' => 'system.caching.CFileCache',
        ),
        'errorHandler' => array(
            'errorAction' => 'site/error'
        ),
        'authManager'  => array(
            'class'           => 'CDbAuthManager',
            'connectionID'    => 'db',
            'itemChildTable'  => 'tbl_auth_item_child',
            'itemTable'       => 'tbl_auth_item',
            'assignmentTable' => 'tbl_auth_assignment',
        ),
        'clientScript' => array(
            'coreScriptPosition' => CClientScript::POS_HEAD,
        ),
        'db'           => require (dirname(__FILE__) . DIRECTORY_SEPARATOR . 'db.php'),
        'phpThumb'     => array(
            'class' => 'ext.EPhpThumb.EPhpThumb',
        ),
        'excel'        => array(
            'class' => 'application.extensions.phpexcel.PHPExcel',
        ),
    ),
    'params'     => require (dirname(__FILE__) . DIRECTORY_SEPARATOR . 'params.php'),
);

/**
 *  Lấy thông tin config từ modules
 */
// Lấy tên của module hiện tại *** Có thể không chính xác
if (isset($config['components']['urlManager']['showScriptName']))
{
    if ($config['components']['urlManager']['showScriptName'] == TRUE)
        $script = $_SERVER['SCRIPT_NAME'];
    else
        $script = str_replace("/index.php", "", $_SERVER['SCRIPT_NAME']);
}

$script      = trim($script, "/");
$request_uri = str_replace($script, "", trim($_SERVER['REQUEST_URI'], "/"));
$request     = explode("/", trim($request_uri, "/"));
$this_module = $request[0];
if ($this_module != "")
{
    $modules_dir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR;
    $handle      = opendir($modules_dir);
    while (false !== ($file        = readdir($handle)))
    {
        if ($file != "." && $file != ".." && is_dir($modules_dir . $file) && $file == $this_module)
        {
            $modules_config = $modules_dir . $file . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'main.php';
            if (file_exists($modules_config))
                $config         = CMap::mergeArray($config, require($modules_config));
        }
    }
    closedir($handle);
}
return $config;
